home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / network / info-sys / www / tkhtml-2.3 / tkhtml-2 / tkHTML-2.3 / tix / bindings / Motif.tcl next >
Encoding:
Text File  |  1995-02-12  |  13.8 KB  |  464 lines

  1. # tk.tcl --
  2. #
  3. # Initialization script normally executed in the interpreter for each
  4. # Tk-based application.  Arranges class bindings for widgets.
  5. #
  6. # $Header: /user6/ouster/wish/library/RCS/tk.tcl,v 1.36 93/08/28 16:45:13 ouster Exp $ SPRITE (Berkeley)
  7. #
  8. # Copyright (c) 1992-1993 The Regents of the University of California.
  9. # All rights reserved.
  10. #
  11. # Permission is hereby granted, without written agreement and without
  12. # license or royalty fees, to use, copy, modify, and distribute this
  13. # software and its documentation for any purpose, provided that the
  14. # above copyright notice and the following two paragraphs appear in
  15. # all copies of this software.
  16. #
  17. # IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  18. # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  19. # OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  20. # CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  21. #
  22. # THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  23. # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  24. # AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  25. # ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  26. # PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  27.  
  28. # Insist on running with compatible versions of Tcl and Tk.
  29.  
  30. scan [info tclversion] "%d.%d" a b
  31. if {$a != 7} {
  32.     error "wrong version of Tcl loaded ([info tclversion]): need 7.x"
  33. }
  34. scan $tk_version "%d.%d" a b
  35. if {($a != 3) || ($b < 3)} {
  36.     error "wrong version of Tk loaded ($tk_version): need 3.3 or later"
  37. }
  38. unset a b
  39.  
  40. # Add Tk's directory to the end of the auto-load search path:
  41.  
  42. lappend auto_path $tk_library
  43.  
  44. # Turn off strict Motif look and feel as a default.
  45.  
  46. set tk_strictMotif 1
  47.  
  48. # ----------------------------------------------------------------------
  49. # Class bindings for various flavors of button widgets.  $tk_priv(window)
  50. # keeps track of the button containing the mouse $tk_priv(relief) saves
  51. # the original relief of the button so it can be restored when the mouse
  52. # button is released, and $tk_priv(buttonWindow) keeps track of the
  53. # window in which the mouse button was pressed.
  54. # ----------------------------------------------------------------------
  55.  
  56. bind Button <Any-Enter> {tk_butEnter %W}
  57. bind Button <Any-Leave> {tk_butLeave %W}
  58. bind Button <1> {tk_butDown %W}
  59. bind Button <ButtonRelease-1> {tk_butUp %W}
  60.  
  61. bind Checkbutton <Any-Enter> {tk_butEnter %W}
  62. bind Checkbutton <Any-Leave> {tk_butLeave %W}
  63. bind Checkbutton <1> {tk_butDown %W}
  64. bind Checkbutton <ButtonRelease-1> {tk_butUp %W}
  65.  
  66. bind Radiobutton <Any-Enter> {tk_butEnter %W}
  67. bind Radiobutton <Any-Leave> {tk_butLeave %W}
  68. bind Radiobutton <1> {tk_butDown %W}
  69. bind Radiobutton <ButtonRelease-1> {tk_butUp %W}
  70.  
  71. # ----------------------------------------------------------------------
  72. # Class bindings for entry widgets.
  73. # ----------------------------------------------------------------------
  74. bind Entry <1> {
  75.     if {[catch {%W index sel.first}] == 0} {
  76.     # OWNS SELECTION --> TURN IT OFF
  77.     %W select from end
  78.     %W select to   end
  79.     }
  80.     %W icursor @%x
  81.     %W select from @%x
  82.     if {[lindex [%W config -state] 4] == "normal"} {focus %W}
  83. }
  84. bind Entry <B1-Motion> {
  85.     %W select to @%x
  86.     %W icursor @%x
  87. }
  88. bind Entry <Shift-1> {
  89.     %W select adjust @%x
  90. }
  91. bind Entry <Shift-B1-Motion> {
  92.     %W select to @%x
  93. }
  94. bind Entry <2> {
  95.     catch {
  96.     %W icursor @%x
  97.     %W insert insert [selection get]
  98.     tk_entrySeeCaret %W
  99.     }
  100. }
  101. bind Entry <KeyPress> {
  102.     if {"%A" != ""} {
  103.     if {[catch {%W index sel.first}] == 0} {
  104.         # OWNS SELECTION --> replace it
  105.         %W delete sel.first sel.last
  106.     }
  107.     %W insert insert %A
  108.     tk_entrySeeCaret %W
  109.     }
  110. }
  111. bind Entry <Delete>    {
  112.     if [catch {%W index sel.first}] {
  113.     # DOES NOT OWN SELECTION
  114.     %W delete [%W index insert]
  115.     } else {
  116.     # OWNS SELECTION --> DELETE SELECTION
  117.     %W delete sel.first sel.last
  118.     }
  119.     tk_entrySeeCaret %W
  120. }
  121.  
  122. bind Entry <Control-d>    {
  123.     if [catch {%W index sel.first}] {
  124.     # DOES NOT OWN SELECTION
  125.     %W delete [%W index insert]
  126.     } else {
  127.     # OWNS SELECTION --> DELETE SELECTION
  128.     %W delete sel.first sel.last
  129.     }
  130.     tk_entrySeeCaret %W
  131. }
  132.  
  133. bind Entry <BackSpace> {
  134.     if [catch {%W index sel.first}] {
  135.     # DOES NOT OWN SELECTION
  136.     tk_entryBackspace %W
  137.     } else {
  138.     # OWNS SELECTION --> DELETE SELECTION
  139.     %W delete sel.first sel.last
  140.     }
  141.     tk_entrySeeCaret %W
  142. }
  143.  
  144. bind Entry <Control-h> {
  145.     if [catch {%W index sel.first}] {
  146.     # DOES NOT OWN SELECTION
  147.     tk_entryBackspace %W
  148.     } else {
  149.     # OWNS SELECTION --> DELETE SELECTION
  150.     %W delete sel.first sel.last
  151.     }
  152.     tk_entrySeeCaret %W
  153. }
  154.  
  155. bind Entry <Right>     {tk_entryMoveCursor %W 1; tk_entrySeeCaret %W}
  156. bind Entry <Control-f> {tk_entryMoveCursor %W 1; tk_entrySeeCaret %W}
  157. bind Entry <Left>      {tk_entryMoveCursor %W -1; tk_entrySeeCaret %W}
  158. bind Entry <Control-b> {tk_entryMoveCursor %W -1; tk_entrySeeCaret %W}
  159. bind Entry <Home>      {%W icursor 0; tk_entrySeeCaret %W}
  160. bind Entry <Control-a> {%W icursor 0; tk_entrySeeCaret %W}
  161. bind Entry <End>       {%W icursor end; tk_entrySeeCaret %W}
  162. bind Entry <Control-e> {%W icursor end; tk_entrySeeCaret %W}
  163. bind Entry <Control-k> {%W delete insert end; tk_entrySeeCaret %W}
  164.  
  165. tk_bindForTraversal Entry
  166.  
  167. # ----------------------------------------------------------------------
  168. # Class bindings for listbox widgets.
  169. # ----------------------------------------------------------------------
  170.  
  171. bind Listbox <1> {%W select from [%W nearest %y]}
  172. bind Listbox <B1-Motion> {%W select to [%W nearest %y]}
  173. bind Listbox <Shift-1> {%W select adjust [%W nearest %y]}
  174. bind Listbox <Shift-B1-Motion> {%W select to [%W nearest %y]}
  175. bind Listbox <2> {%W scan mark %x %y}
  176. bind Listbox <B2-Motion> {%W scan dragto %x %y}
  177.  
  178. # ----------------------------------------------------------------------
  179. # Class bindings for scrollbar widgets.  When strict Motif is requested,
  180. # the bindings use $tk_priv(buttons) and $tk_priv(activeFg) to set the
  181. # -activeforeground color to -foreground when the mouse is in the window
  182. # and restore it when the mouse leaves.
  183. # ----------------------------------------------------------------------
  184.  
  185. bind Scrollbar <Any-Enter> {
  186.     if $tk_strictMotif {
  187.     set tk_priv(activeFg) [lindex [%W config -activeforeground] 4]
  188.     %W config -activeforeground [lindex [%W config -foreground] 4]
  189.     }
  190. }
  191. bind Scrollbar <Any-Leave> {
  192.     if {$tk_strictMotif && ($tk_priv(buttons) == 0)} {
  193.     %W config -activeforeground $tk_priv(activeFg)
  194.     }
  195. }
  196. bind Scrollbar <Any-ButtonPress> {incr tk_priv(buttons)}
  197. bind Scrollbar <Any-ButtonRelease> {incr tk_priv(buttons) -1}
  198.  
  199. # ----------------------------------------------------------------------
  200. # Class bindings for scale widgets.  When strict Motif is requested,
  201. # the bindings use $tk_priv(buttons) and $tk_priv(activeFg) to set the
  202. # -activeforeground color to -foreground when the mouse is in the window
  203. # and restore it when the mouse leaves.
  204. # ----------------------------------------------------------------------
  205.  
  206. bind Scale <Any-Enter> {
  207.     if $tk_strictMotif {
  208.     set tk_priv(activeFg) [lindex [%W config -activeforeground] 4]
  209.     %W config -activeforeground [lindex [%W config -sliderforeground] 4]
  210.     }
  211. }
  212. bind Scale <Any-Leave> {
  213.     if {$tk_strictMotif && ($tk_priv(buttons) == 0)} {
  214.     %W config -activeforeground $tk_priv(activeFg)
  215.     }
  216. }
  217. bind Scale <Any-ButtonPress> {incr tk_priv(buttons)}
  218. bind Scale <Any-ButtonRelease> {incr tk_priv(buttons) -1}
  219.  
  220. # ----------------------------------------------------------------------
  221. # Class bindings for menubutton widgets.  Variables used:
  222. # $tk_priv(posted) -        keeps track of the menubutton whose menu is
  223. #                currently posted (or empty string, if none).
  224. # $tk_priv(inMenuButton)-    if non-null, identifies menu button
  225. #                containing mouse pointer.
  226. # $tk_priv(relief) -        keeps track of original relief of posted
  227. #                menu button, so it can be restored later.
  228. # $tk_priv(dragging) -        if non-null, identifies menu button whose
  229. #                menu is currently being dragged in a tear-off
  230. #                operation.
  231. # $tk_priv(focus) -        records old focus window so focus can be
  232. #                returned there after keyboard traversal
  233. #                to menu.
  234. # ----------------------------------------------------------------------
  235.  
  236. bind Menubutton <Any-Enter> {
  237.     set tk_priv(inMenuButton) %W
  238.     if {[lindex [%W config -state] 4] != "disabled"} {
  239.     if {!$tk_strictMotif} {
  240.         %W config -state active
  241.     }
  242.     }
  243. }
  244. bind Menubutton <Any-Leave> {
  245.     set tk_priv(inMenuButton) {}
  246.     if {[lindex [%W config -state] 4] == "active"} {
  247.     %W config -state normal
  248.     }
  249. }
  250. bind Menubutton <1> {tk_mbButtonDown %W}
  251. bind Menubutton <Any-ButtonRelease-1> {
  252.     if {($tk_priv(posted) == "%W") && ($tk_priv(inMenuButton) == "%W")} {
  253.     [lindex [$tk_priv(posted) config -menu] 4] activate 0
  254.     } else {
  255.     tk_mbUnpost
  256.     }
  257. }
  258.  
  259. # The binding below is trickier than it looks.  It's important to check
  260. # to see that another menu is posted in the "if" statement below.
  261. # The check is needed because some window managers (e.g. mwm in
  262. # click-to-focus mode) cause a button-press event to be preceded by
  263. # a B1-Enter event;  we don't want to process that B1-Enter event (if
  264. # we do, the grab may get mis-set so that the menu is non-responsive).
  265.  
  266. bind Menubutton <B1-Enter> {
  267.     set tk_priv(inMenuButton) %W
  268.     if {([lindex [%W config -state] 4] != "disabled")
  269.         && ($tk_priv(posted) != "")} {
  270.     if {!$tk_strictMotif} {
  271.         %W config -state active
  272.     }
  273.     tk_mbPost %W
  274.     }
  275. }
  276. bind Menubutton <2> {
  277.     if {($tk_priv(posted) == "")
  278.         && ([lindex [%W config -state] 4] != "disabled")} {
  279.     set tk_priv(dragging) %W
  280.     [lindex [$tk_priv(dragging) config -menu] 4] post %X %Y
  281.     }
  282. }
  283. bind Menubutton <B2-Motion> {
  284.     if {$tk_priv(dragging) != ""} {
  285.     [lindex [$tk_priv(dragging) config -menu] 4] post %X %Y
  286.     }
  287. }
  288. bind Menubutton <ButtonRelease-2> {set tk_priv(dragging) ""}
  289.  
  290. # ----------------------------------------------------------------------
  291. # Class bindings for menu widgets.  $tk_priv(x) and $tk_priv(y) are used
  292. # to keep track of the position of the mouse cursor in the menu window
  293. # during dragging of tear-off menus.  $tk_priv(window) keeps track of
  294. # the menu containing the mouse, if any.
  295. # ----------------------------------------------------------------------
  296.  
  297. bind Menu <Any-Enter> {set tk_priv(window) %W; %W activate @%y}
  298. bind Menu <Any-Leave> {set tk_priv(window) {}; %W activate none}
  299. bind Menu <Any-Motion> {
  300.     if {$tk_priv(window) == "%W"} {
  301.     %W activate @%y
  302.     }
  303. }
  304. bind Menu <1> {
  305.     if {$tk_priv(grab) != ""} {
  306.     grab $tk_priv(grab)
  307.     }
  308. }
  309. bind Menu <ButtonRelease-1> {tk_invokeMenu %W}
  310. bind Menu <2> {set tk_priv(x) %x; set tk_priv(y) %y}
  311. bind Menu <B2-Motion> {
  312.     if {$tk_priv(posted) == ""} {
  313.     %W post [expr %X-$tk_priv(x)] [expr %Y-$tk_priv(y)]
  314.     }
  315. }
  316. bind Menu <B2-Leave> { }
  317. bind Menu <B2-Enter> { }
  318. bind Menu <Escape> {tk_mbUnpost}
  319. bind Menu <Any-KeyPress> {tk_traverseWithinMenu %W %A}
  320. bind Menu <Left> {tk_nextMenu -1}
  321. bind Menu <Right> {tk_nextMenu 1}
  322. bind Menu <Up> {tk_nextMenuEntry -1}
  323. bind Menu <Down> {tk_nextMenuEntry 1}
  324. bind Menu <Return> {tk_invokeMenu %W}
  325.  
  326. # ----------------------------------------------------------------------
  327. # Class bindings for text widgets. $tk_priv(selectMode) holds one of
  328. # "char", "word", or "line" to indicate which selection mode is active.
  329. # ----------------------------------------------------------------------
  330. bind Text <1> {
  331.     %W tag remove sel 0.0 end
  332.     set tk_priv(selectMode) char
  333.     %W mark set insert @%x,%y
  334.     %W mark set anchor insert
  335.     if {[lindex [%W config -state] 4] == "normal"} {focus %W}
  336. }
  337. bind Text <Double-1> {
  338.     set tk_priv(selectMode) word
  339.     %W mark set insert "@%x,%y wordstart"
  340.     tk_textSelectTo %W insert
  341. }
  342. bind Text <Triple-1> {
  343.     set tk_priv(selectMode) line
  344.     %W mark set insert "@%x,%y linestart"
  345.     tk_textSelectTo %W insert
  346. }
  347. bind Text <B1-Motion> {
  348.     tk_textSelectTo %W @%x,%y
  349.     %W mark set insert @%x,%y
  350. }
  351. bind Text <Shift-1> {
  352.     tk_textResetAnchor %W @%x,%y
  353.     tk_textSelectTo %W @%x,%y
  354. }
  355. bind Text <Shift-B1-Motion> {
  356.     tk_textSelectTo %W @%x,%y
  357.     %W mark set insert @%x,%y
  358. }
  359. bind Text <2> {
  360.     catch {
  361.     %W mark set insert @%x,%y
  362.     %W insert insert [selection get]
  363.     %W mark set insert @%x,%y
  364.     %W yview -pickplace insert
  365.     }
  366. }
  367. bind Text <Left> {
  368.     %W mark set insert insert-1c
  369.     %W yview -pickplace insert
  370. }
  371. bind Text <Right> {
  372.     %W mark set insert insert+1c
  373.     %W yview -pickplace insert
  374. }
  375. bind Text <Up> {
  376.     %W mark set insert insert-1l
  377.     %W yview -pickplace insert
  378. }
  379. bind Text <Down> {
  380.     %W mark set insert insert+1l
  381.     %W yview -pickplace insert
  382. }
  383.  
  384. # Motif style behavior
  385. bind Text <KeyPress> {
  386.     if {"%A" != ""} {
  387.     catch {
  388.         # owns selection -> delete it
  389.         if {[%W tag ranges sel] != {}} {
  390.         eval %W delete [%W tag ranges sel]
  391.         }
  392.     }
  393.     %W insert insert %A
  394.     %W yview -pickplace insert
  395.     }
  396. }
  397.  
  398. bind Text <Return> {
  399.     catch {
  400.     if {[%W tag ranges sel] != {}} {
  401.         # owns selection -> delete it
  402.         eval %W delete [%W tag ranges sel]
  403.     }
  404.     }
  405.     %W insert insert \n
  406.     %W yview -pickplace insert
  407. }
  408. bind Text <Delete> {
  409.     if {[%W tag ranges sel] != {}} {
  410.     eval %W delete [%W tag ranges sel]
  411.     } else {
  412.     %W delete insert
  413.     }
  414.     %W yview -pickplace insert
  415. }
  416.  
  417. bind Text <Control-d> {
  418.     if {[%W tag ranges sel] != {}} {
  419.     eval %W delete [%W tag ranges sel]
  420.     } else {
  421.     %W delete insert
  422.     }
  423.     %W yview -pickplace insert
  424. }
  425.  
  426. bind Text <BackSpace> {
  427.     if {[%W tag ranges sel] != {}} {
  428.     eval %W delete [%W tag ranges sel]
  429.     } else {
  430.     tk_textBackspace %W
  431.     }
  432.     %W yview -pickplace insert
  433. }
  434.  
  435. bind Text <Control-h> {
  436.     if {[%W tag ranges sel] != {}} {
  437.     eval %W delete [%W tag ranges sel]
  438.     } else {
  439.     tk_textBackspace %W
  440.     }
  441.     %W yview -pickplace insert
  442. }
  443.  
  444.  
  445. tk_bindForTraversal Text
  446.  
  447. # Initialize the elements of tk_priv that require initialization.
  448.  
  449. set tk_priv(buttons) 0
  450. set tk_priv(buttonWindow) {}
  451. set tk_priv(dragging) {}
  452. set tk_priv(focus) {}
  453. set tk_priv(grab) {}
  454. set tk_priv(inMenuButton) {}
  455. set tk_priv(posted) {}
  456. set tk_priv(selectMode) char
  457. set tk_priv(window) {}
  458.  
  459. tixDefaultAutoBind
  460.  
  461. proc tixSetBinding::Motif {} {
  462.     # Just a dummy to make sure that this file is loaded
  463. }
  464.